package com.kai.service.enums;

import com.kai.service.data.dto.wechat.receive.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.FieldDefaults;

import java.util.Objects;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public enum WechatMsgTypeEnum {

    text("文本消息", TextMessageReceiveDto.class),
    image("图片消息", ImageMessageReceiveDto.class),
    voice("语音消息", VoiceMessageReceiveDto.class),
    video("视频消息", VideoMessageReceiveDto.class),
    shortvideo("小视频消息", ShortVideoMessageReceiveDto.class),
    location("地理位置消息", LocationMessageReceiveDto.class),
    link("链接消息", LinkMessageReceiveDto.class);

    String desc;
    Class<? extends MessageReceiveDto> clazz;

    /**
     * 根据消息类型获取消息对象类
     *
     * @param msgType
     * @return
     */
    public static Class<? extends MessageReceiveDto> getMessageClass(String msgType) {
        for (WechatMsgTypeEnum wechatMsgTypeEnum : WechatMsgTypeEnum.values()) {
            if (Objects.equals(wechatMsgTypeEnum.name(), msgType)) {
                return wechatMsgTypeEnum.clazz;
            }
        }

        return MessageReceiveDto.class;
    }
}
